#include "linkfabric/SDK.hpp"
#include <iostream>
#include <unistd.h>

using namespace linkfabric;

int main() {   
    linkfabric::MemLink mem;
    mem.init("/dev/mydevice");
    linkfabric::SDK sdk(mem);

    int ch = sdk.openChannel();

    sdk.onMessage(ch, [](uint8_t type, auto fields) {
        std::cout << "📥 Message type: " << int(type) << std::endl;
        for (auto& [tag, val] : fields) {
            std::cout << "Tag " << int(tag) << ": " << val << std::endl;
        }
    });

    sdk.sendMessage(ch, 0x01, {
        {0x01, "paul"},
        {0x02, "hello world"}
    }, "secret");

    sdk.run();
    sleep(2);
    sdk.closeChannel(ch);
}
